<extend name="./Application/Admin/View/Layout/application.html"/>

<block name="content">
    <div class="row">
        <div class="col-md-9">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <h3 class="panel-title">友情链接</h3>
                </div>
                <div class="panel-body">
                    <form action="" method="post" id="form">
                        <table class="table table-hover">
                            <thead>
                            <tr>
                                <th>
                                    <input type="checkbox" id="check_all"/>
                                </th>
                                <th>编号</th>
                                <th>名称</th>
                                <th>网址</th>
                                <th>排序</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <volist name="links" id="link">
                                <tr data-id="{{$link.id}}">
                                    <th>
                                        <!--！！！！！这里为什么无法使用id? 因为id是唯一的，不能重复！！！！！！！！！！！！！！！！-->
                                        <input type="checkbox" class="check_child" name="id[]" value="{{$link.id}}"/>
                                    </th>
                                    <th scope="row">{{$link.id}}</th>
                                    <td class="name">{{$link.name}}</td>
                                    <td class="url"><a href="{{$link.url}}" target="_blank">{{$link.url}}</a></td>
                                    <td class="col-sm-2">
                                        <input type="hidden" name="id[]" value="{{$link.id}}"/>
                                        <input type="text" name="sort_order[]" value="{{$link.sort_order}}"/>
                                    </td>
                                    <td>
                                        <a href="#editlink" class="edit" data-toggle="modal"><span
                                                class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a>
                                        <a href="#deletelink" class="delete" data-toggle="modal"><span
                                                class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
                                    </td>
                                </tr>
                            </volist>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>
        </div>
        <div class="col-md-2">
            <div class="list-group ">
                <a href="#" class="list-group-item list-group-item-success" style="text-align: center"
                   data-toggle="modal" data-target="#addlink">增加</a>
                <a href="#" class="list-group-item list-group-item-info" id="delete_all" style="text-align: center" data-toggle="modal"
                   data-target="#deleteAlllink">删除</a>
                <a href="#" class="list-group-item list-group-item-warning" id="sort_order" style="text-align: center"
                   data-toggle="modal" data-target="#sort_order">排序</a>

            </div>
        </div>
    </div>
    <!--模态框增加-->
    <div class="modal fade" tabindex="-1" role="dialog" id="addlink">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">增加友情链接</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" action="{{:U('add')}}" method="post">
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">网站名称:</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="name" id="inputEmail3"
                                       placeholder="请输入友情连接名字">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputPassword3" class="col-sm-2 control-label">网址:</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="url" id="inputPassword3" value="http://"
                                       placeholder="请输入友情连接网址">
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-danger" data-dismiss="modal">关 闭</button>
                            <button type="submit" class="btn btn-success">保 存</button>
                        </div>
                    </form>
                </div>

            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    <!--模态框编辑-->
    <div class="modal fade" tabindex="-1" role="dialog" id="editlink">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">修改友情链接</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" action="{{:U('Link/edit')}}" method="post">
                        <input type="hidden" name="id" class="edit_id">
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">网站名称:</label>
                            <div class="col-sm-10">
                                <input type="text" class="edit_name form-control" name="name"
                                       placeholder="请输入友情连接名字">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputPassword3" class="col-sm-2 control-label">网址:</label>
                            <div class="col-sm-10">
                                <input type="text" class="edit_url form-control" name="url"
                                       placeholder="请输入友情连接网址">
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-danger" data-dismiss="modal">关 闭</button>
                            <button type="submit" class="btn btn-success">保 存</button>
                        </div>
                    </form>
                </div>

            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    <!--删除单条-->
    <div class="modal fade" id="deletelink" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">

            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="ModalLabel">删除友情链接</h4>
                </div>

                <div class="modal-body">
                    <p>确认要删除当前友情链接吗？</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                    <a type="submit" class="btn btn-danger delete_one">确 认</a>
                </div>
            </div>
        </div>
    </div>

</block>
<block name="js">
    <script>

        $(function () {
            $('.edit').click(function () {
                var id = $(this).parents('tr').data('id');
                var name = $(this).parent().siblings('.name').text();
                var url = $(this).parent().siblings('.url').text();
                $('.edit_id').val(id);
                $('.edit_name').val(name);
                $('.edit_url').val(url);
            });

            $('.delete').click(function () {
                var id = $(this).parents('tr').data('id');
                var href = "/Admin/Link/delete/id" + id;
                $('.delete_one').attr('href', href).submit();

            });
            $('#check_all').click(function () {
                var check = $(this).prop('checked');
                $('.check_child').prop('checked',check);
            });
            $('#delete_all').click(function(){

                $('#form').attr('action',"{{:U('delete_all')}}").submit();
            });
            $('#sort_order').click(function(){
                var action = "{{:U('sort_order')}}";
                $('#form').attr('action',action).submit();
            })

        })


    </script>

</block>